Hello and welcome to this select show in this show.
We will be creating a couple of functions to respond to the key and key down events in the previous
lectures.
We created event listeners to listen out for when key up when the key down events occur.
To save time I have already created a piece of code.
This is a function here that will control the key down events so whenever there is a when they read
the key is down on the keyboard.
This function is what will be fired up to respond to that.
So let me just run through the function here.
I started with a keyword function.
That's what you need to type to create a function followed by the name of the function.
It's always good to name your functions as closely as possible to the activity you want them to perform.
So this function here is called Key down.
HANDLER it takes in one parameter which is represented by this E P variable here.
It takes an event as the parameter so if the key on the cursor on the keyboard is press that it is down
that means it is pressed and that is an event so it will store the information in this e variable.
So what will then happen once that information is stored.
Implemented in IF statement so what this IF statement is saying is that the perimeter is where you specify
be.
If statement is saying if this event which is this E.
Here is the key called is e wars to 39.
So the key chord 39 represents when the right cursor is pressed.
So what this code is saying is if that she is press press down is 39.
That means you are holding on or you press in down the right cursor So that equals to true else.
If you are not press in down the right key or right cursor if you are press in if the key you are pressin
which means if e doors key could equal so 37.
If the key is 37 instead that means you are actually presson on the left cursor or left key.
In that case that value is also true.
So what this piece of code is saying is that any time we press on any of these keys the key number 39
which represents the right cursor or key number 37 which represent the left cursor.
So any time either of those keys are pressed that means the function.
This function here will be fired up and that information will be stored inside.
This is variable so any time you press any of those key variable here stores that information and fires
up this function.
Next we are going to create another variable that will counteract this function.
So this foreign churn will kick off when these conditions are true.
That means when either of these keys are pressed.
So what happens when those keys are unlocked pressed.
So when the keys are released that means the keys will be up.
So are we going to create another function called key up handler and Paulson is going to take one parameter
which is the event variable that will store the information that the key is naturally up.
In that case the variables the variables will be false because if he's not pressed them is up.
All right so this piece of code here is the function for the key up Handler.
It takes him warm perimeter which is the whole of the event.
The perimeter is represented by this guy here is also known as event.
So if we when we know that from the first could hear this fence function when the keys are pressed that
means the key is down and the value is true.
This phone chant is the opposite.
So when the keys are released and they are not pressed the information is variable.
Tell this function that the keys are up they are not being pressed.
In that case the value is equal to force.
The moment we pressed the key and the key goes down it becomes the value changes.
True.
And this fell's function here will be fired up.
So when the keys are down it's Phong shell will kick off and when the key are released that means the
unlock Press function will kick off.
So this too will handle when the key is up and when the key is down.
So for a quick summary of what the functions do the first function will be fired off when the key on
the keyboard is pressed down.
So when the right key or the left key is pressed down the key down function will be fired up because
that information is stored in the variable that would trigger the function to kick-off.
The second option is when the key is not pressed.
That means the key handler will be fired up and that function will kick off bullet parameters but function
stakes in the value of e which is the event variable.
So when the keys are pressed now be values set true and when the key is not pressed when they're up.
The variable is set to force.
Thank you so much for your time and watch it in the next lecture.
We are going to be creating some logic that we can use to control the movement of the pad.
Thank you so much.
Bye for now.